package com.bigtotoro.shuiyincamera;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;

import com.bigtotoro.shuiyincamera.my_arts.MyPhotosFragment;
import com.bigtotoro.shuiyincamera.my_arts.MyShowsFragment;
import com.bigtotoro.shuiyincamera.my_arts.MyVideosFragment;
import com.bigtotoro.shuiyincamera.tabentity.TabEntity;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;

/**
 * 我的作品
 */
public class MyArtsActivity extends BaseActivity {
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private ArrayList<CustomTabEntity>mTabEntitis = new ArrayList<>();
    public ViewPager viewPager;
    public CommonTabLayout tabLayout;
    private String []titles = {"图片","视频"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_arts);
        initBase();
        initView();
        initViewPager();
    }

    private void initViewPager() {
        for (int i = 0;i<titles.length;i++){
            mTabEntitis.add(new TabEntity(titles[i],R.drawable.arrow_down,R.drawable.arrow_down));
        }
        //添加分页
//        mFragments.add(MyShowsFragment.newInstance(0));
//        mFragments.add(MyShowsFragment.newInstance(1));
        mFragments.add(new MyPhotosFragment());
        mFragments.add(new MyVideosFragment());

        viewPager = findViewById(R.id.myviewPager);

        tabLayout = findViewById(R.id.tl);
//        tabLayout.setIndicatorWidth(tabLayout.getWidth()/2);
        tabLayout.setTextsize(15);
        tabLayout.setIconVisible(false);
        tabLayout.setTabData(mTabEntitis);
        tabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                viewPager.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        viewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                tabLayout.setCurrentTab(position);

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }
    public class MyPagerAdapter extends FragmentPagerAdapter {

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }
    }

    private void initView() {


    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("MyArtsActivity");//统计页面
        MobclickAgent.onResume(this);
    }
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("MyArtsActivity");//统计页面
        MobclickAgent.onPause(this);
    }
}
